#include "Comm.hpp"
#include "Fifo.hpp"
#include <unistd.h>

int main()
{
    // 1.生成key
    key_t key = GetKey();
    cout << "key sucess,key:" << ToHex(key) << endl;

    // 2.创建shmid
    int shmid = CreatShmid(key, defaultsize);
    cout << "shmid sucess,shmid:" << shmid << endl;

    // //*.shmctl的另外作用
    // ShmctlDebug(shmid);

    // 4. 将共享内存和进程进行挂接(关联)
    char *addr = (char *)AttchShm(shmid);

    // 0.引入管道
    Fifo fifo;
    Sync syn;
    syn.OpenRead();

    // 可以进行通信了
    for (;;)
    {
        if(!syn.Wait()) break;
        cout << "shm content: " << addr << std::endl;
    }

    sleep(10);
    // llast 去关联
    DeAttchShm(addr);

    // last 删除共享内存
    DeleteShmid(shmid);

    return 0;
}